package com.group4.banner.controller;


import com.github.pagehelper.PageInfo;
import com.group4.banner.entity.Banner;
import com.group4.banner.service.BannerService;
import com.study.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author cloud
 * @since 2022-03-10
 */
@RestController
@RequestMapping("/banner")
@Api("CrmBannerController")
public class CrmBannerController {
    @Autowired
    private BannerService bannerService;

    /**
     * 增加banner,添加使用postmapping
     * @param banner
     */
    @PostMapping("/add")
    public void addBanner(@RequestBody Banner banner){

        bannerService.addBanner(banner);
    }

    /**
     * 根据id查询banner,查询这里使用GetMapping
     * @param
     */
    @GetMapping("/findById/{id}")
    @ApiOperation(value = "根据id查询课程")
    public ResponseResult findBannerById(@PathVariable String id){

        return new ResponseResult(bannerService.fingById(id));
    }

    /**
     * 查询所有的banner
     * @param
     */
    @GetMapping("/findAll")
    public ResponseResult findBannerByAll(){
         List<Banner> all = bannerService.getAll();
         return new ResponseResult(all);
    }

    @RequestMapping("/page/{pageNum}")
    public ResponseResult page(@PathVariable int pageNum){
         PageInfo<Banner> pageinfo = bannerService.pageinfo(pageNum);
         return new ResponseResult(pageinfo);
    }


}

